home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- ***** Gadget Demo 2 *****
- ***** *****
- ***** by John J. Karcher *****
- ***** *****
- ***** 4 August 1992 *****
- ***** 10 Jan 1993 mvk *****
- ***** *****
- **************************************************************************/
-
- /*
- This program opens up a window with a single gadget in it, using
- egsgadbox.library. This one is a little smarter; it waits for
- the user to hit the close gadget before dying. It also prints
- a little message to the console if you click on the action gadget.
-
- This demonstrates how to get a close gadget, deal with idcmp
- messages, and react to action gadget messages.
- */
-
- #include <stdio.h>
- #include <exec/types.h>
- #include <egs/egsintui.h>
- #include <egs/egsgadbox.h>
- #include <proto/all.h>
- #include <egs/proto/all.h>
-
- struct EI_Window *CreateWindow(void);
-
- #define ACTION_GAD_ID 1000
-
-
- struct Library *EGSIntuiBase;
- struct Library *EGBBase;
-
- struct EB_GadContextNode *GadCon;
-
-
- struct EI_Window *CreateWindow(void)
- {
- struct EI_Window *ret = NULL;
- EB_GadBoxPtr root;
-
- if (GadCon = EB_CreateGadContext(NULL, NULL, -1, -1))
- {
- if (root = EB_CreateTextAction(GadCon, "Push Me", ACTION_GAD_ID, EB_FILL_ALL))
- {
- if (EB_ProcessGadBoxes(GadCon, root))
- {
- GadCon->NewWin->Title = "EGS Gadget Demo 2";
- GadCon->NewWin->IDCMPFlags |= (EI_iCLOSEWINDOW | EI_iGADGETUP);
- GadCon->NewWin->Flags |= EI_WINDOWCENTER;
- GadCon->NewWin->Bordef.SysGadgets |= EI_WINDOWCLOSE;
- GadCon->NewWin->Width = 200;
- GadCon->NewWin->Height= 100;
- ret = EI_OpenWindow(GadCon->NewWin);
- }
- }
- }
-
- return ret;
- }
-
- main()
- {
- struct EI_Window *Win;
- struct EI_EIntuiMsg *IMsg;
- struct EI_Gadget *TempGad;
- BYTE quit = 0;
-
- if (EGSIntuiBase = OpenLibrary("egsintui.library", 0))
- {
- if (EGBBase = OpenLibrary("egsgadbox.library", 0))
- {
- if (Win = CreateWindow())
- {
- while (!quit)
- {
- WaitPort(Win->UserPort);
- if (IMsg = (struct EI_EIntuiMsg *)GetMsg(Win->UserPort))
- {
- if (IMsg->Class == EI_iCLOSEWINDOW)
- {
- quit = 1;
- }
- if (IMsg->Class == EI_iGADGETUP)
- {
- TempGad = (struct EI_Gadget *)IMsg->IAddress;
- if (TempGad->GadgetID == ACTION_GAD_ID)
- {
- printf("You pressed me!\n");
- }
- }
- ReplyMsg((struct Message *)IMsg);
- }
- }
- }
- if (Win) EI_CloseWindow(Win);
- if (GadCon) EB_DeleteGadContext(GadCon);
- CloseLibrary(EGBBase);
- }
- CloseLibrary(EGSIntuiBase);
- }
- }
-